import React,{Component} from "react";
import {connect} from 'react-redux'
import {Redirect} from "react-router-dom";
import {
    NavBar,
    InputItem,
    Button,
    TextareaItem
} from "antd-mobile"

import {Update} from "../../redux/actions";
import HeadSelector from "../../components/head-select/head-selector";
class Laobaninfo extends Component{
    state = { header: '', // 头像名称
        info: '', // 职位简介
        post: '', // 职位名称
        company: '', // 公司名称
        salary: '' // 工资
    }
    change = (item,val) =>{

        this.setState({[item]:val})
}
    baocun =()=>{
        console.log(this.state)
        this.props.Update(this.state)

    }
    setHeader= (header)=>{
        this.setState({header:header})
    }
    render() {
        const {header} = this.props
        if(header){
            //用户信息已经完善，跳转到用户的主界面
            return <Redirect to='/laoban'></Redirect>
        }
        return(
            <div>
                <NavBar>老板信息完善</NavBar>
                <HeadSelector setHeader = {this.setHeader}></HeadSelector>
                <InputItem placeholder='请输入招聘职位' onChange={(val)=>this.change("post",val)}>招聘职位：</InputItem>
                <InputItem placeholder='请输入公司名称' onChange={(val)=>this.change("company",val)}>公司名称：</InputItem>
                <InputItem placeholder='请输入职位薪资' onChange={(val)=>this.change("salary",val)}>职位薪资：</InputItem>
                <TextareaItem title='职位要求' rows={3} onChange={(val)=>this.change("info",val)}></TextareaItem>
                <Button style={{backgroundColor:"green"}} onClick={this.baocun}>保存</Button>
            </div>
        )
    }
}
export default connect(
    state=>(state.user),
    {Update}
)(Laobaninfo)